//
//  ChangeInfoVC.m
//  HDYS
//
//  Created by qianfeng on 15-5-6.
//  Copyright (c) 2015年 kay. All rights reserved.
//

#import "ChangeInfoVC.h"
#import "PersonInfoViewController.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height


@interface ChangeInfoVC ()

@end

@implementation ChangeInfoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden = YES;
    
    self.titleTextField.text = [[self.infoDic allValues] lastObject];
    self.titleTextField.clearButtonMode = UITextFieldViewModeWhileEditing | UITextFieldViewModeUnlessEditing;
    
    [self createNavi];
}

- (void)createNavi {
    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44)];
//    navView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:navView];
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn.frame = CGRectMake(10, 20, 40, 20);
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [cancleBtn addTarget:self action:@selector(cancleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:cancleBtn];
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(SCREEN_WIDTH - 10 - 40, 20, 40, 20);
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [saveBtn addTarget:self action:@selector(saveBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:saveBtn];
}

- (void)cancleBtnClick:(UIButton *)btn {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)saveBtnClick:(UIButton *)btn {
    [self dismissViewControllerAnimated:YES completion:nil];
    
    if ([self.delegate respondsToSelector:@selector(updatePersonInfoWithDic:)]) {
        [self.infoDic setObject:self.titleTextField.text forKey:[self.infoDic allKeys].lastObject];
        [self.delegate updatePersonInfoWithDic:self.infoDic];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
